package com.uchengwang.ui.cm_ui.uu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.uu.bean.ChooseMoodBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by U城网 on 2018/4/17.
 */

public class ChooseMoodAdapter extends BaseAdapter{
    private Context context;
    private List<ChooseMoodBean> list;

    public ChooseMoodAdapter(Context context, List<ChooseMoodBean> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ChooseMoodVh holder = null;
        if (view == null){
            holder = new ChooseMoodVh();
            view = LayoutInflater.from(context).inflate(R.layout.layout_choose_mood_item, parent, false);

            holder.mood_image = view.findViewById(R.id.mood_image);
            holder.mood_name = view.findViewById(R.id.mood_name);

            AutoUtils.auto(view);
            view.setTag(holder);
        }else {
            holder = (ChooseMoodVh) view.getTag();
        }

        ChooseMoodBean bean = list.get(position);
        holder.mood_name.setText(bean.getTitle());
        ImageManager.getInstance().loadImage(context, holder.mood_image, bean.getResId(), ImageManager.ImageType.NARMOL);

        return view;
    }

    private class ChooseMoodVh{
        private ImageView mood_image;
        private TextView mood_name;
    }
}
